def is_prime(n):
    W = True
    for i in range (2,int(n**0.5)+1):
        if n%i==0:
            W=False
            break
    return(W)

number_r=''
x=input()
word_k=x.split()
for i in range (len(word_k)):
    if word_k[i]=="zero": number_r+='0'
    if word_k[i]=="one": number_r+='1'
    if word_k[i]=="two": number_r+='2'
    if word_k[i]=="three": number_r+='3'
    if word_k[i]=="four": number_r+='4'
    if word_k[i]=="five": number_r+='5'
    if word_k[i]=="six": number_r+='6'
    if word_k[i]=="seven": number_r+='7'
    if word_k[i]=="eight": number_r+='8'
    if word_k[i]=="nine": number_r+='9'
if number_r != '': 
    number_r = int(number_r)
else:
    number_r = 0
spis6=[]
for i in range (100,999+1):
    if is_prime(i)==True:
        spis6.append(i)
if number_r < 100 or number_r > 999 or len(word_k) != 3:
    print("Wrong input")
else:
    min_r=10**6
    for i in range(len(spis6)):
        if abs(number_r-spis6[i])<=min_r:
            min_r=abs(number_r-spis6[i])
            min_n=i
    print(spis6[min_n])
